<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>service-details</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

		<link rel="stylesheet" href="../../../../css/mui.min.css">
		<link rel="stylesheet" href="../../../../css/global.css">
		<link rel="stylesheet" href="../../../../css/style.css">
		<link rel="stylesheet" href="../../../../css/mui.picker.css">
		<link rel="stylesheet" href="../../../../css/mui.poppicker.css">
		<style type="text/css">
			.mui-btn-block{
				font-size: 16px;
				color: #a9a9a9;
				border: 0;
		    }
			input[type=text]{margin-bottom: 0;}
			input[disabled]{color:#a9a9a9;opacity:1;padding: 0;}
			.d_ipt{
				padding: 0 !important;
			}
			.selectDate{
				color: #333;
			}
			.details_con .clum{
				height: auto;
			}
			.details_con .clum .txt{
				float: none;
				line-height: initial;
			}
			.mui-btn-block{
				margin-bottom: 0;
				line-height: 20px;
				width: 100%;
				text-align: right;
				white-space: normal;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 id="title" class="mui-title">Error Report</h1>
		</header>
		<div class="mui-content">
			<div class="details_con">
				<div hidden>
					<input type="hidden" id="id" />
					<input type="hidden" id="planId" />
					<input type="hidden" id="noticeId" />
					<input type="hidden" id="helpId" />
				</div>
				<div class="clum">
					<span class="name">服务编号</span>
					<span class="txt" id="serviceNo" style="line-height: 20px;width: auto;text-align: right;padding: 15px 0;"></span>
				</div>
				<div class="clum">
					<span class="name">Error发生时间<em class="t_red">*</em></span>
					<button id='errorDate' type="button" class="selectDate">请选择时间</button>
				</div>
				<div class="clum nobor">
					<span class="name">客户英文单位名称<em class="t_red">*</em></span>
					<input type="text" id="enCompanyName" class="d_ipt" placeholder="请输入单位名称" />
				</div>
				<div class="clum autoHeight">
					<span class="name">问题描述<em class="t_red">*</em></span>
					<div class="clear"></div>
					<textarea maxlength="1000" class="textarea" id="problemStatement" style="margin-bottom: 0;color: #333;" placeholder="请输入问题描述"></textarea> 
					<p class="d_tip">注：请用英文描述故障排除的过程及结果</p>
				</div>
				<div class="clum autoHeight">
					<span class="name">原因<em class="t_red">*</em></span>
					<div class="clear"></div>
					<textarea maxlength="1000" class="textarea" id="rootCause" placeholder="请输入原因" style="color: #333;"></textarea> 
				</div>
				<div class="clum autoHeight">
					<span class="name">补救措施<em class="t_red">*</em></span>
					<div class="clear"></div>
					<textarea maxlength="1000" class="textarea" id="correctiveActionTaken" placeholder="请输入补救措施" style="color: #333;"></textarea>
				</div>
				<div class="clum">
					<span class="name">跟踪日期<em class="t_red">*</em></span>
					<button id='trackDate'  type="button" class="selectDate">请选择时间</button>
				</div>
				<!-- <div class="clum">
					<span class="name">Error代码类别</span>
					<input type="text" id="parentCode" class="d_ipt" placeholder="下拉选" />
				</div> -->
				<div class="clum">
					<span class="name">Error代码类别</span>
					<span class="txt">
						<input type="hidden" id="parentCodeValue" />
						<button id='parentCode' class="mui-btn mui-btn-block mui-btn-select" type='button' style="color: #333;">缺件</button>
					</span>
				</div>
				<!-- <div class="clum">
					<span class="name">Error代码<em class="t_red">*</em></span>
					<input type="text" id="errCode" class="d_ipt" placeholder="下拉选" />
				</div> -->
				<div class="clum">
					<span class="name">Error代码<em class="t_red">*</em></span>
					<span class="txt">
						<input type="hidden" id="errCodeValue" />
						<button id='errCode' class="mui-btn mui-btn-block mui-btn-select" type='button' style="color: #333;">请选择</button>
					</span>
				</div>
				<div class="clum">
					<span class="name">Error分类</span>
					<input type="text" id="errType" class="d_ipt" disabled="disabled" style="padding: 0;"/>
				</div>
				<div class="clum autoHeight">
					<span class="name">Error代码描述</span>
					<div class="clear"></div>
					<div class="textarea" id="errLongdesc" style="color: #A9A9A9;"></div>
				</div>
				<div class="clum">
					<span class="name">Error责任人</span>
					<input maxlength="100" type="text" id="errResponman" class="d_ipt" placeholder="" disabled="disabled"/>
				</div>
				<div class="my-content-cell" id="partsList">
					<div class="inline-block" id="pjcgqd">
						<em>备件列表</em>
						<span class="mui-icon mui-icon-arrowright arrow-right-position"></span>
					</div>
				</div>
				<!-- <div class="my-content-cell" id="addParts">
					<div class="inline-block" id="pjcgqd">
						<em>添加备件</em>
						<span class="mui-icon mui-icon-arrowright arrow-right-position"></span>
					</div>
				</div> -->
				<div class="my-content-cell" id="pictureList">
					<div class="inline-block" id="pjcgqd">
						<em>图片信息列表</em>
						<span class="mui-icon mui-icon-arrowright arrow-right-position"></span>
					</div>
				</div>
				
			</div>
			<div class="btn_box">
				<button class="fl" id="saveBtn">保存草稿</button>
				<button class="fr red" id="submitBtn">正式提交</button>
			</div>
			<div style="height: 50px;"></div>
		</div>

		<!-- js代码 start -->

		<!-- 基础js start -->
		<script src="../../../../js/mui.min.js"></script>
		<script src="../../../../js/utils/h.js"></script>
		<script src="../../../../js/constant.js"></script>
		<script src="../../../../js/common.js"></script>
		<script src="../../../../js/utils/base64.js"></script>
		<script src="../../../../js/utils/md5.js"></script>
		<script src="../../../../js/utils/sortMap.js"></script>
		<script src="../../../../js/utils/http.js"></script>
		<script src="../../../../js/app.js"></script>
		<!-- 基础js end -->
		<script src="../../../../js/mui.picker.js"></script>
		<script src="../../../../js/mui.poppicker.js"></script>
		<script src="../../../../js/utils/rolldate.min.js"></script>
		<script src="../../../../js/fse/service/report/error/error.js"></script>

		<script type="text/javascript" charset="utf-8">
			var serviceNo
			var planId
			var noticeId
			var id
			// 提交状态 0未提交 1已提交
			var submitStatus = 0;
			/*
			* 禁止交互事件
			*/
			function noInteraction() {
				if(submitStatus && submitStatus == '1') {
					h('#errorDate').attr('disabled', 'disabled')
					h('#enCompanyName').attr('readonly', 'readonly')
					h('#problemStatement').attr('readonly', 'readonly')
					h('#rootCause').attr('readonly', 'readonly')
					h('#correctiveActionTaken').attr('readonly', 'readonly')
					h('#trackDate').attr('disabled', 'disabled')
					h('#parentCode').attr('disabled', 'disabled')
					h('#errCode').attr('disabled', 'disabled')
					// h('#errLongdesc').attr('readonly', 'readonly')
					h('#errResponman').attr('readonly', 'readonly')
					h('#addParts').hide()
					h('#saveBtn').hide()
					h('#submitBtn').hide()
				}
			}
			
			(function($, doc) {
				$.init();
			
				$.plusReady(function() {
					// 初始化时间控件
					initDateTimeControls()
					
					var self = plus.webview.currentWebview();
					submitStatus = self.submitStatus;
					serviceNo = self.serviceNo
					h('#serviceNo').html(serviceNo)
					console.log(serviceNo)
					noInteraction()
					ajaxGet(BASE_URL + "cc/error/report/detailErrorReport", {
						id: self.errId
					}, function(data) {
						noInteraction()
						if (data.code === 200) {
							h('#id').val(data.data.id)
							h('#serviceNo').html(serviceNo)
							h('#errorDate').html(data.data.errorDate)
							h('#enCompanyName').val(data.data.enCompanyName)
							// h("#enCompanyName").attr('disabled','disabled');
							h('#problemStatement').val(data.data.problemStatement)
							h('#rootCause').val(data.data.rootCause)
							h('#correctiveActionTaken').val(data.data.correctiveActionTaken)
							h('#trackDate').html(data.data.trackDate)
							h('#parentCode').html(data.data.parentValue)
							h('#parentCodeValue').val(data.data.parentCode)
							h('#errCode').html(data.data.errValue)
							h('#errCodeValue').val(data.data.errCode)
							h('#errType').val(data.data.errType)
							h('#errLongdesc').html(data.data.errLongdesc)
							h('#errResponman').val(data.data.errResponman)
							h('#helpId').val(data.data.helpId)
							planId = data.data.planId
							h('#planId').val(planId)
							noticeId = data.data.noticeId
							h('#noticeId').val(noticeId)
						} else {
							app.toast(data.msg)
						}
					}, function(errorMsg) {
						noInteraction()
						app.toast(errorMsg)
					});
					
					// 保存按钮触发事件
					h('#saveBtn').tap(function() {
						h(this).attr('disabled','disabled');
						app.hideSoftKeybord()
						updateErrorData("正在保存...", function(data) {
							app.closeWaiting()
							if (data.code === 200) {
								id = data.data.id;
								app.toast("保存成功")
								// 查找需要跳转的页面，并指定刷新的方法
								var erroOrHot = plus.webview.getWebviewById('view/service/report/errorhot/erroOrHot.html');
								if (erroOrHot) {
									erroOrHot.close()
								}
								mui.back();
							} else {
								h('#saveBtn').removeAttr('disabled');
								h('#submitBtn').removeAttr('disabled');
								app.toast(data.msg)
							}
						})
					})
					
					// 提交
					h('#submitBtn').tap(function() {
						h(this).attr('disabled','disabled');
						app.hideSoftKeybord()
						updateErrorData("正在提交...", function(data) {
							if (data.code === 200) {
								id = data.data.id;
								errorSubmit();
							} else {
								h('#saveBtn').removeAttr('disabled');
								h('#submitBtn').removeAttr('disabled');
								app.toast(data.msg)
							}
						})
					})
					
					//备件列表
					h('#partsList').tap(function() {
						app.hideSoftKeybord()
						app.jumpTo('/view/service/report/errorhot/sparePartsList.html','view/service/report/errorhot/sparePartsList.html',{
							serviceNo:serviceNo,
							helpId:h('#helpId').val(),
							submitStatus:submitStatus,
							portType: 3
						})
					})
					//添加备件
					h('#addParts').tap(function() {
						app.hideSoftKeybord()
						app.jumpTo('/view/service/report/errorhot/sparePartsAdd.html','view/service/report/errorhot/sparePartsAdd.html',{
							serviceNo:serviceNo,
							helpId:h('#helpId').val(),
							portType: 3
						})
					})
					//图片列表
					h('#pictureList').tap(function() {
						app.hideSoftKeybord()
						app.jumpTo('/view/service/picture/list.html','view/service/picture/list.html',{serviceNo:serviceNo,helpId:h('#helpId').val(),syncFlag:0,submitStatus:submitStatus})
					})
					
					h("#parentCode").tap(function(){
						app.hideSoftKeybord()
						var parentCodePicker = new mui.PopPicker();
						parentCodePicker.setData([{
							value: 'N',
							text: '缺件'
						}, {
							value: 'P',
							text: '故障'
						}, {
							value: 'R',
							text: '破损'
						}, {
							value: 'S',
							text: '现场条件不具备'
						}, {
							value: 'T',
							text: '客户期望未满足'
						}]);
						parentCodePicker.show(function(items) {
							console.log(JSON.stringify(items[0]));
							h('#parentCode').html(items[0].text)
							h("#parentCodeValue").val(items[0].value)
							h('#errCode').html("请选择")
							h('#errCodeValue').val("")
							h("#errType").val("");
							h("#errLongdesc").html("")
							h("#errResponman").val("");
							parentCodePicker.dispose()
						});
					})
					
					h("#errCode").tap(function(){
						var parentCode = h("#parentCode").html();
						console.log(parentCode)
						ajaxGetJson(BASE_URL + 'cc/dict/getParamTablesErr', {
							parentValue: parentCode
						}, function(data) {
							app.closeWaiting()
							console.log(JSON.stringify(data))
							if (!data) {
								app.toast("无数据")
								return
							}
							var arr = new Array();
							var map1 = new Map();
							var map2 = new Map();
							var map3 = new Map();
							for(var i=0;i<data.length;i++){
								var dts = data[i];
								var errCode = dts.Err_Code;
								var errValue = dts.Err_Code+":"+dts.Err_Value;
								var obj_1 = { value:errCode,text:errValue};
								map1.set(errCode,dts.Err_CodeType+":"+dts.Err_Classifica);
								map2.set(errCode,dts.Err_LongDESC);
								map3.set(errCode, dts.Err_ResponMan);
								arr.push(obj_1);
							}
							var errCodePicker = new mui.PopPicker();
							errCodePicker.setData(arr);
							errCodePicker.show(function(items) {
								h('#errCode').html(items[0].text)
								h('#errCodeValue').val(items[0].value)
								h("#errType").val(map1.get(items[0].value));
								h("#errLongdesc").html(map2.get(items[0].value))
								h("#errResponman").val(map3.get(items[0].value))
								errCodePicker.dispose()
							});
						});
					})
					
				});
			}(mui, document));
		</script>
		<!-- js代码 end -->

	</body>

</html>
